package com.bwie.sixth.commerce.controller;

import java.util.Arrays;
import java.util.Map;


import com.bwie.sixth.commerce.config.OSSFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bwie.sixth.commerce.entity.BuyEntity;
import com.bwie.sixth.commerce.service.BuyService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 用户可以看到的拼团活动的页面
 *
 * @author lzl
 * @email 1601711944@gmail.com
 * @date 2021-09-10 15:07:15
 */

@RestController
@RequestMapping("commerce/buy")
public class BuyController {
    @Autowired
    private BuyService buyService;



    @RequestMapping("/upload")
    public String upload(MultipartFile file) throws Throwable {
        String s = OSSFileUtil.uploadFile(file);
        return s;
    }
    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = buyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{buyId}")

    public R info(@PathVariable("buyId") Integer buyId){
		BuyEntity buy = buyService.getById(buyId);

        return R.ok().put("buy", buy);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody BuyEntity buy){
		buyService.save(buy);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody BuyEntity buy){
		buyService.updateById(buy);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Integer[] buyIds){
		buyService.removeByIds(Arrays.asList(buyIds));

        return R.ok();
    }

}
